package com.haieros.www.purerunshowsystem.broadcast;

import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
import com.haieros.www.purerunshowsystem.MainActivity;

/**
 * Created by W520 on 2017/11/24.
 */

public class UpdateReceiver extends BroadcastReceiver {
    @Override

    public void onReceive(Context context, Intent intent) {

        String action = intent.getAction();
        if (action.equals("android.intent.action.PACKAGE_REPLACED")) {
            Toast.makeText(context,"升级了一个安装包，重新启动此程序", Toast.LENGTH_SHORT).show();
            Log.i("升级了一个安装包，重新启动此程序","=====升级了一个安装包，重新启动此程序");
//            if (intent.getDataString().equals("package:com.haieros.www.purerunshowsystem")) {
//                ComponentName name = new ComponentName("com.haieros.www.purerunshowsystem", "com.haieros.www.purerunshowsystem.StartActivity");
//                Intent mIntent = new Intent();
//                mIntent.setComponent(name);
//                mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                context.startActivity(mIntent);
//            }
////            Intent intent2 = new Intent(context, MainActivity.class);
////            intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
////            context.startActivity(intent2);
        }

        if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) {     // install
//            if(intent.getDataString().equals("package:com.haieros.www.purerunshowsystem"))
//            {
//                Toast.makeText(context,"添加了一个安装包，重新启动此程序", Toast.LENGTH_SHORT).show();
//                Log.i("添加了一个安装包，重新启动此程序","=====添加了一个安装包，重新启动此程序");
//                Intent intent3 = new Intent(context, MainActivity.class);
//                intent3.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                context.startActivity(intent3);
//            }


        }
    }
}
